<template>
  <el-dialog
    v-model="visible"
    title="个人信息"
    width="400px"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
  >
    <div class="user-info-container">
      <div class="avatar-container">
        <el-avatar :size="100" :src="defaultAvatar" />
      </div>
      <div class="info-list">
        <div class="info-item">
          <span class="label">用户名：</span>
          <span class="value">{{ userInfo.userCode }}</span>
        </div>
        <div class="info-item">
          <span class="label">昵称：</span>
          <span class="value">{{ userInfo.userName }}</span>
        </div>
        <div class="info-item">
          <span class="label">状态：</span>
          <el-tag :type="userInfo.userState === '1' ? 'success' : 'danger'" size="small">
            {{ userInfo.userState === '1' ? '启用' : '禁用' }}
          </el-tag>
        </div>
        <div class="info-item">
          <span class="label">创建时间：</span>
          <span class="value">{{ userInfo.createTime }}</span>
        </div>
      </div>
    </div>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="visible = false">关闭</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>
import { ref, reactive } from 'vue';
import { get } from '@/common';

const visible = ref(false);
const defaultAvatar = ref('/default-avatar.svg');
const userInfo = reactive({
  userCode: '',
  userName: '',
  roleName: '',
  userState: '',
  createTime: ''
});

// 打开弹窗
const open = async (userId) => {
  visible.value = true;
  try {
    const result = await get(`/user/info/${userId}`);
    Object.assign(userInfo, result.data);
  } catch (error) {
    console.error('Failed to fetch user info:', error);
  }
};

defineExpose({
  open
});
</script>

<style scoped>
.user-info-container {
  padding: 20px;
}

.avatar-container {
  text-align: center;
  margin-bottom: 24px;
}

.info-list {
  max-width: 300px;
  margin: 0 auto;
}

.info-item {
  display: flex;
  margin-bottom: 16px;
  align-items: center;
}

.label {
  width: 80px;
  color: #606266;
  font-size: 14px;
}

.value {
  flex: 1;
  color: #303133;
  font-size: 14px;
}

.dialog-footer {
  text-align: center;
}
</style> 